package com.itbaiyun.ai.controller;

import com.itbaiyun.ai.assistance.MyAssistant;
import com.itbaiyun.ai.bean.UserMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai")
public class AiController {
    @Autowired
    private MyAssistant assistant;

//    @PostMapping("/chat")
//    public void chat() {
//        String chat1 = assistant.chat(1, "你好,你是谁?");
//        System.out.println(chat1);
//        String chat2 = assistant.chat(1, "我是家希");
//        System.out.println(chat2);
//        String chat3 = assistant.chat(1, "我是谁");
//        System.out.println(chat3);
//    }

    @PostMapping(value = "/chat1", produces = "text/stream;charset=utf-8")
    public Flux<String> chat(@RequestBody UserMessage userMessage) {
        return assistant.chat(userMessage.getMemoryId(), userMessage.getMessages());
    }

}
